
//引入网络库
import { get, post } from "../../util/util.js"

// 获取全局应用程序实例对象
var app = getApp();

// 创建页面实例对象
Page({
  /**
   * 页面名称
   */
  name: "addyyjl",
  /**
   * 页面的初始数据
   */

  data: {
    uid:'',
    shangyingStr: '2018-05-01',
    currentItemDylx: '',
    dylxList: [],
    dylxKey: '',
    dylxArr: [],
    nameStr: '',
    videoNameStr: '',
    currentItemJslx: '',
    jslxList: [],
    jslxKey: '',
    jslxArr: [],
    daoyanStr: '',
    yirenStr: '',
    otherStr: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
 
  },
  onLoad: function (o) {
    var that = this;
    console.log("新增演绎经历===uid===" + o.uid);
    that.setData({
      uid: o.uid
    })
    //影片类型配置
    post("/film/createconf", {}).then(data => {
      //影片类型 crew_type role_type
      var dylxData = [];
      var dylxStr = [];
      for (var key in data.data.crew_type) {
        dylxData.push(key);
        dylxStr.push(data.data.crew_type[key]); 
      }
      var jslxData = [];
      var jslxStr = [];
      for (var key in data.data.role_type) {
        jslxData.push(key);
        jslxStr.push(data.data.role_type[key]);
      }

      that.setData({
        dylxList: dylxData,
        dylxArr: dylxStr,

        jslxList: jslxData,
        jslxArr: jslxStr,
      })
      
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },
  /**
   * formId获取
   */
  submitInfo: function (e) {
    var that = this;
    console.log('表单submitInfo:==================', e);
    console.log('表单id:==================', e.detail.formId);

    post("/user/addFormid", { uid: that.data.uid, form_id: e.detail.formId }).then(data => {
    })
  },
  /**
  * 监听日期picker选择器
  */
  listenerDatePickerSelected: function (e) {
    var that = this;
    that.setData({
      shangyingStr: e.detail.value
    })
    console.log("获取点击 上映时间 字段" + that.data.shangyingStr)
  },
  /**
    * 获取点击 电影类型 字段
    */
  getDylx: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);

    that.setData({
      currentItemDylx: index,
      dylxKey: that.data.dylxList[index],
    })
    console.log("获取点击 电影类型 字段" + that.data.dylxKey)
  },
  /**
   * 获取点击 角色类型 字段
   */
  getJslx: function (e) {
    var that = this;
    var index = parseInt(e.currentTarget.dataset.index);

    that.setData({
      currentItemJslx: index,
      jslxKey: that.data.jslxList[index],
    })
    console.log("获取点击 角色类型 字段" + that.data.jslxKey)
  },
  //角色名称
  nameInput: function (e) {
    var that = this;
    that.setData({
      nameStr: e.detail.value
    })
    console.log("获取点击 角色名称 字段" + that.data.nameStr)
  },
  //电影名称
  videoNameInput: function (e) {
    var that = this;
    that.setData({
      videoNameStr: e.detail.value
    })
    console.log("获取点击 电影名称 字段" + that.data.videoNameStr)
  },
  //合作导演：
  daoyanInput: function (e) {
    var that = this;
    that.setData({
      daoyanStr: e.detail.value
    })
    console.log("获取点击 合作导演： 字段" + that.data.daoyanStr)
  },
  //合作艺人：
  yirenInput: function (e) {
    var that = this;
    that.setData({
      yirenStr: e.detail.value
    })
    console.log("获取点击 合作艺人： 字段" + that.data.yirenStr)
  },
  //其他
  otherInput: function (e) {
    var that = this;
    that.setData({
      otherStr: e.detail.value
    })
    console.log("获取点击 其他 字段" + that.data.otherStr)
  },
  yyjlSub: function () {
    var that = this;
    var param = {};
    wx.showLoading({
      title: '加载中',
    })
    param.uid = that.data.uid;
    if (that.data.otherStr != "") {
      param.other = that.data.otherStr;
    } 
    if (that.data.yirenStr != '' && that.data.daoyanStr != ''
      && that.data.jslxKey != '' && that.data.videoNameStr != ''
      && that.data.nameStr != '' && that.data.dylxKey != ''
      && that.data.shangyingStr != '') {
      param.co_actor = that.data.yirenStr;
      param.co_director = that.data.daoyanStr;
      param.role_type = that.data.jslxKey;
      param.film_name = that.data.videoNameStr;
      param.role_name = that.data.nameStr;
      param.crew_type = that.data.dylxKey;
      param.year = that.data.shangyingStr;
      post("/actor/addExperience", param).then(data => {
        console.log("actor/addExperience==" + data.data);
        wx.hideLoading();
        wx.navigateBack({
          delta: -1
        });
      })
    } else {
      wx.hideLoading();
      wx.showModal({
        title: '提示',
        content: '请填写完整资料',
        showCancel: false,  
        confirmText: '确定'
      })
    }

  }
})

